Skip to content

Deprecate externalContext and migrate to Map-backed getObject/putObject#4070

Open
ramanathan1504 wants to merge 3 commits into
apache:2.xfrom
ramanathan1504:issue-2351
Open

Deprecate externalContext and migrate to Map-backed getObject/putObject#4070
ramanathan1504 wants to merge 3 commits into
apache:2.xfrom
ramanathan1504:issue-2351

Conversation

@ramanathan1504

@ramanathan1504 ramanathan1504 commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

This PR deprecates the externalContext methods in LoggerContext (API and Core) and replaces the internal storage with a ConcurrentHashMap accessible via putObject and getObject.

Key Changes:
1.Marked setExternalContext and getExternalContext as @Deprecated (since 2.27.0).
2.Refactored LoggerContext to use a Map-backed storage to prevent collisions between frameworks (e.g., Spring Boot and Log4j-Web).
3.Maintained backward compatibility for Spring Boot by using a legacy key in the internal map.

Outcome:
This work resolves the servlet context resolution issue in composite configurations.
Fixes #2351

@vy vy changed the title [LOG4J2-2351] Fix servlet context resolution in composite configurati… Fix servlet context resolution in composite configuration Apr 30, 2026
@ppkarwasz ppkarwasz requested a review from Copilot May 31, 2026 10:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes servlet context propagation for web lookups when Log4j is initialized with a composite configuration (comma-separated log4jConfiguration locations), ensuring ${web:*} lookups (notably ${web:servletContextName}) resolve consistently between single-file and composite modes.

Changes:

  • Update Log4jContextFactory#getContext(..., List<URI> configLocations, ...) to correctly handle externalContext passed as a Map.Entry<String, Object> by routing it through the ContextSelector entry-based overload.
  • Add a regression test that initializes Log4j via Log4jWebLifeCycle using a composite config and asserts ${web:servletContextName} resolves.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
log4j-jakarta-web/src/test/java/org/apache/logging/log4j/web/WebLookupTest.java Adds a regression test covering ${web:servletContextName} resolution for composite configuration initialization.
log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java Ensures Map.Entry external context is applied via the selector so web lookups can retrieve the ServletContext in composite mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ramanathan1504 ramanathan1504 changed the title Fix servlet context resolution in composite configuration Deprecate externalContext and migrate to Map-backed getObject/putObject Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Missing servlet context in web lookup when using composite configuration

4 participants